home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / CD32 / CD32_Support / examples / SA_Examples / nonvolatile / GetNVInfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-31  |  2.3 KB  |  107 lines

  1. /* GetNVInfo.c
  2.  * 
  3.  * test nonvolatile.library/GetNVInfo()
  4.  * 
  5.  * 
  6.  */
  7.  
  8. /* Includes --------------------------------------------- */
  9. #include <exec/types.h>
  10. #include <exec/libraries.h>
  11. #include <exec/memory.h>
  12. #include <dos/dos.h>
  13. #include <dos/rdargs.h>
  14. #include <libraries/nonvolatile.h>
  15. #include <clib/exec_protos.h>
  16. #include <clib/dos_protos.h>
  17. #include <clib/nonvolatile_protos.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20.  
  21. #include <pragmas/nonvolatile_pragmas.h>
  22. #include "nv.h"
  23.  
  24. /* Defines ------------------------------------------ */
  25. #define PROGNAME "GetNVInfo"
  26. #define ERRMSG_LIBNOOPEN "Couldn't open %s V%ld (or better)!\n"
  27. #define TEMPLATE "KILLREQ/S"
  28.  
  29. struct Opts {
  30.     LONG killReq;
  31. };
  32.  
  33. /* Protos ------------------------------------------ */
  34. static VOID GoodBye(int);
  35. static LONG doInit(VOID);
  36.  
  37. /* Globals --------------------------------------- */
  38. struct Library *NVBase;
  39. struct NVInfo *nvi;
  40. struct RDArgs *rdargs;
  41. struct Opts opts;
  42.  
  43. VOID main(int argc, UBYTE *argv[]) {
  44.     BOOL killReq;
  45.  
  46.     if (!doInit()) {
  47.         GoodBye(RETURN_FAIL);
  48.     }
  49.  
  50.     killReq = ((opts.killReq) ? TRUE : FALSE);
  51.  
  52.     if (nvi = GetNVInfo(killReq)) {
  53.         Printf("Got NVInfo at $%08lx:\n", nvi);
  54.         Printf("  nvi_MaxStorage  = %lu\n", nvi->nvi_MaxStorage);
  55.         Printf("  nvi_FreeStorage = %lu\n", nvi->nvi_FreeStorage);
  56.     }
  57.     else {
  58.         PrintFault(IoErr(), PROGNAME);
  59.         PutStr("GetNVInfo() failed!\n");
  60.     }
  61.  
  62.     GoodBye(RETURN_OK);
  63. }
  64.  
  65. /* GoodBye ===============================================
  66.    Clean-exit routine.
  67.  */
  68. static VOID GoodBye(int rc) {
  69.  
  70.     if (nvi) {
  71.         PutStr("Calling FreeNVData(nvi)...\n");
  72.         FreeNVData(nvi);
  73.     }
  74.  
  75.     if (NVBase) {
  76.         CloseLibrary(NVBase);
  77.     }
  78.  
  79.     if (rdargs) {
  80.         FreeArgs(rdargs);
  81.     }
  82.  
  83.     exit(rc);
  84. }
  85.  
  86. /* doInit =============================================
  87.  * Open libraries, call ReadArgs() if necessary.
  88.  * Returns TRUE for success, FALSE otherwise.
  89.  */
  90. static LONG doInit(VOID) {
  91.  
  92.     rdargs = ReadArgs(TEMPLATE, (LONG *)&opts, NULL);
  93.     if (!rdargs) {
  94.         PrintFault(IoErr(),PROGNAME);
  95.         return(FALSE);
  96.     }
  97.  
  98.     NVBase = OpenLibrary("nonvolatile.library", 40L);
  99.     if (!NVBase) {
  100.         Printf(ERRMSG_LIBNOOPEN, "nonvolatile.library", 40L);
  101.         return(FALSE);
  102.     }
  103.  
  104.     return(TRUE);
  105. }
  106.  
  107.